package club.pchome.scheduled;

import java.util.Date;

import club.pchome.dto.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import club.pchome.controller.AutoSignContoller;
import club.pchome.controller.UnprocessedController;
import club.pchome.controller.UserInfoController;
import club.pchome.service.AutoSignService;
import club.pchome.service.InterfaceService;
import club.pchome.util.DateUtil;

/**
 * @author Watler
 * 正式环境--新网--的任务调度
 */
@Slf4j
//@Component
public class BTask {
	@Autowired
	AutoSignContoller autoSignContoller;
	
	@Autowired
	AutoSignService autoSignService;
	
	@Autowired
	UnprocessedController unprocessedController;

	@Autowired
	UserInfoController userInfoController;
	
	@Autowired
	InterfaceService interfaceService;
	
	@Scheduled(cron="0 */6 9-21 * * ?")
	public void processed() {
		System.out.println("-------------------发送短信提醒--------------------------");
		try {
//			unprocessedController.unprocessedSendSms();
			unprocessedController.unprocessedList();
			Thread.sleep(20000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		System.out.println(DateUtil.hhmmss.format(new Date()) + "********待完成的任务********每6分钟执行一次");
	}
 

	/**
	 *  定时扫描签到, 每5分钟扫描一次
	 */
//	@Scheduled(cron="0 */5 * * * ?")
	public void autoSign() {
		try {
			autoSignContoller.signNew();
			Thread.sleep(20000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		System.out.println(DateUtil.hhmmss.format(new Date()) + "********签到任务********每5分钟执行一次");
	}

//	@Scheduled(cron="0 */15 * * * ?")
	public void accountList() {

		try {
			userInfoController.updataUser(null , null);
			Thread.sleep(20000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		System.out.println(DateUtil.hhmmss.format(new Date()) + "********更新账户********每15分钟执行一次");
	}

//	@Scheduled(cron="0 */5 * * * ?")
	public void animalList() {

		try {
			userInfoController.feedAnimal();
			Thread.sleep(20000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		System.out.println(DateUtil.hhmmss.format(new Date()) + "********喂养动物********每5分钟执行一次");
	}
	
	
	/***
	 * 	更新新加入的用户资料
	 */
//	@Scheduled(cron="0 */5 * * * ?")
	public void checkAccountStatus() {

		try {
			autoSignContoller.checkAccountStatus();
			Thread.sleep(20000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		System.out.println(DateUtil.hhmmss.format(new Date()) + "********更新账户********每5分钟执行一次");
	}



//    @Scheduled(cron = "0 0 0 * * ?")
	public void isAutoSign() {

		try {
			System.out.println(DateUtil.hhmmss.format(new Date()) + "********重置用户可签到,每天凌晨执行********");
			autoSignService.updateSignStatus();
			System.out.println(DateUtil.hhmmss.format(new Date()) + "********查询签到会员是否过期,每天凌晨执行********");
			autoSignService.isAutoSign();
			System.out.println(DateUtil.hhmmss.format(new Date()) + "********重置用户接口使用数据,每天凌晨执行********");
			interfaceService.updateUseNum();
			Thread.sleep(20000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		System.out.println(DateUtil.hhmmss.format(new Date()) + "********每天凌晨执行任务完成********");
	}

}